﻿using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

namespace EnumGenerator
{
		static class Program
		{
				/// <summary>
				/// The main entry point for the application.
				/// </summary>
				[STAThread]
				static void Main()
				{
						//To catch exceptions in Main thread
						Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
						//To catch exceptions in other threads
						AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

						Application.EnableVisualStyles();
						Application.SetCompatibleTextRenderingDefault(false);
						Application.Run(new FormMain());
				}

				static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
				{
						HandleException(e.Exception);
				}

				static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
				{
						HandleException(e.ExceptionObject as Exception);
				}

				static void HandleException(Exception pEx)
				{
						System.Diagnostics.EventLog.WriteEntry("Application", pEx.Message, EventLogEntryType.Error, 1111);
						MessageBox.Show(pEx.Message, pEx.TargetSite.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
		}
}
